﻿using System;
using System.Drawing;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
using WFControlLibrary;
namespace 任务状态
{
    public partial class 源设置 : Form
    {
        public 源设置()
        {
            InitializeComponent();
        }

        private void 源设置_Load(object sender, EventArgs e)
        {
            
            ControlIni.Load(this);
            int count = 0;
            foreach (string text in src_comboBox1.Items)
            {
                if (text.Length > 5) count++;
            }
            if (count <= 0)
            {
                src_comboBox1.Items.Clear();
                src_comboBox1.Items.Add("https://qt.gtimg.cn/q=");
                src_comboBox1.Items.Add("https://web.sqt.gtimg.cn/q=");
                src_comboBox1.SelectedIndex = 0;
            }
            label_srcset.Text = "源设置";
        }

        private void 源设置_FormClosing(object sender, FormClosingEventArgs e)
        {
            ControlIni.Save(this);
        }

        private void src_comboBox1_TextUpdate(object sender, EventArgs e)
        {
           
        }
        private string GetHTMLByURLRequest(string URL)
        {
            WebRequest.DefaultWebProxy = null;
            WebRequest request = WebRequest.Create(URL);
            WebResponse resp = request.GetResponse();
            Stream stream = resp.GetResponseStream();
            StreamReader sr = new StreamReader(stream, Encoding.Default);
            string result = sr.ReadToEnd();
            stream.Close();
            sr.Close();
            return result;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            bool exists = false;
            foreach (string text in src_comboBox1.Items)
            {
                if (text == src_comboBox1.Text)
                {
                    exists = true;
                    break;
                }
            }
            if (!exists)
            {
                src_comboBox1.Items.Add(src_comboBox1.Text);
            }
            else
            {
                MessageBox.Show("该项已存在！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                String rest = GetHTMLByURLRequest(src_comboBox1.Text + "sz000519");
                MessageBox.Show(rest, "测试响应", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception E)
            {
                MessageBox.Show(E.Message, "测试异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private bool dragging = false;
        private Point dragCursorPoint;
        private Point dragFormPoint;
        private void panel6_MouseDown(object sender, MouseEventArgs e)
        {
            dragging = true;
            dragCursorPoint = Cursor.Position;
            dragFormPoint = this.Location;
        }

        private void panel6_MouseMove(object sender, MouseEventArgs e)
        {
            if (dragging)
            {
                Point diff = Point.Subtract(Cursor.Position, new Size(dragCursorPoint));
                this.Location = Point.Add(dragFormPoint, new Size(diff));
            }
        }

        private void panel6_MouseUp(object sender, MouseEventArgs e)
        {
            dragging = false;
        }
    }
}
